home *** CD-ROM | disk | FTP | other *** search
/ D.I.S.C. 5 / D.I.S.C. 5.adf / sources / direct_selection_opt.s next >
Encoding:
Text File  |  1989-01-11  |  896 b   |  40 lines

  1. ; --------------------------------------
  2. ; - direct-selection sorting algorithm -
  3. ; - optimized version by JPN/Level 4   -
  4. ; --------------------------------------
  5. org    $40000
  6. load    $40000
  7.  
  8. num_elements=30
  9. a:
  10.         lea    data_list,a0    ; table for elements
  11.         moveq    #00,d0        ; outer loop counter (x)
  12. outer:    
  13.         move.w    d0,d1        ; inner loop counter (y)
  14.         move.w    d0,d2        ; index for smallest (j=x)
  15.         move.w    (a0,d2.w),d3    ; a(j) -> d3        
  16. inner:
  17.         cmp.w    (a0,d1.w),d3    ; a(y) < a(y) ???
  18.         blt.s    smaller
  19.         move.w    d1,d2        ; j=y
  20.         move.w    (a0,d2.w),d3    ; a(j) -> d3            
  21. smaller:
  22.         addq.w    #02,d1        ; next y value
  23.         cmp.w    #num_elements*2,d1
  24.         bne.s    inner        ; next y
  25.         move.w    (a0,d0.w),d4    ; a(x) => d4
  26.         move.w    d3,(a0,d0.w)    
  27.         move.w    d4,(a0,d2.w)
  28.         addq.w    #02,d0        ; next x value
  29.         cmp.w    #num_elements*2,d0
  30.         bne.s    outer
  31.         rts            
  32.  
  33. data_list:
  34.     dc.w 5,2,3,1,6,8,9,7,4,0
  35.     dc.w 5,2,3,-1,6,8,9,7,4,0
  36.     dc.w 5,2,3,1,6,8,9,7,4,0
  37. list_end:
  38.  
  39.  
  40.